<cfmodule template="../../tag/layout.cfm">
<cfinclude template="../../inc/lib.cfm">
<cfscript>
	if( structKeyExists(rc, "type")  && rc.type > 0 ){
		type = rc.type;
	}else{
		categoryid = 0;
	}
	
	if( structKeyExists(rc, "checkedids")  && rc.checkedids > 0 ){
		checkedids = rc.checkedids;
	}else{
		checkedids = 0;
	}
</cfscript>
<!--- 表格显示 --->
<table id="grid"></table>
<div id="toolbar" style="display: none;">
	<form id="searchForm">
		<table>
			<tr>
				<td>标题</td>
				<td><input name="subject" style="width: 100px;" /></td>
				<td>创建时间</td>
				<td>
					<input name="created_ge"  class="easyui-datebox" style="width:100px"/>
					-
					<input name="created_le"  class="easyui-datebox" style="width:100px"/>
				</td>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',fw.serializeObject($('#searchForm')));">过滤</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
				</td>
			</tr>
		</table>
	</form>
</div>
</cfmodule>
<script type="application/javascript">
var closeDialog = function($dialog) {
	$dialog.dialog('destroy');
}

var submitForm = function($dialog, $materialids)  {
	var ids = [];
	var rows = $('#grid').datagrid('getSelections');
	for(var i=0; i<rows.length; i++){
		ids.push(rows[i].id);
	}
	$materialids.val(ids.join(','));
	
	$materialids.click();
	
	$dialog.dialog('destroy');
};

$(function(){
	
	var gird;
	grid = $('#grid').datagrid({
		fit: false,
		border:false,
		collapsible:false,
		pagination:true,
		singleSelect:false,
		rownumbers:true,
		sortName:'id',
		idField:'id',
		sortOrder:'desc',
		toolbar : '#toolbar',
		url:'?action=adsmaterial.list&type=<cfoutput>#type#</cfoutput>',
		columns:[[
			{field:'ck',checkbox:true},
			{field:'id',title:'ID',width:40,sortable:true},
			{field:'type',title:'类型',width:40,sortable:true,align:'center',
			formatter:function(value,row){
				if(value == 0){
					v = '<img src="assets/images/font.png">';
				}else{
					v = '<img src="assets/images/image.png">';
				}
				return v;
			}},
			{field:'subject',title:'标题',width:200,sortable:true},
			{field:'url',title:'链接地址',width:60,sortable:true,
			formatter:function(value,row){
				return '<a href="'+value+'" target="_blank">查看链接</a>'
			}},
			{field:'urltarget',title:'弹出方式',width:60,sortable:true},
			{field:'width',title:'宽度',width:50,sortable:true},
			{field:'height',title:'高度',width:50,sortable:true},
			{field:'seq',title:'排序',width:50,sortable:true}
		]],
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
			
			var checkedids = '<cfoutput>#checkedids#</cfoutput>';
			$.each(data.rows, function(index, item){
				if( $.inArray(item.id.toString(),checkedids.split(',')) != -1){
					 grid.datagrid('checkRow', index);
				}
				
			});
		}
	});
	
	
});
</script>